<?php
/* 
Plugin Name: WoW Armory 
Plugin URI: http://timsworld.nfshost.com/wordpress-plugins/wow-armory-wp-plugin/ 
Description: Shows your character's Armory info  
Version: 6.0
Author: Tim (SeiferTim) Hely
Author URI: http://timsworld.nfshost.com
*/  



if (isset($_GET['deleteit']) && isset($_GET['delete'])) {
	$clear_count = 0;
	foreach( (array) $_GET['delete'] as $clear_name ) {
		delete_option($clear_name);
		$clear_count++;
	}
	?>
	<div id="message" class="updated fade">
		<p><?php echo sprintf('Cleared %s caches.', $clear_count); ?></p>
	</div>
	<?php
}


require_once(ABSPATH . 'wp-includes/class-snoopy.php');
require_once('includes/functions.php');

	class WoWArmory {
    var $plugin_folder = '';
    /* -- List of Models -- */
	var $modelNames = array(
		1 => array(
				0 => 'humanmale',
				1 => 'humanfemale',
			),
		2 => array(
				0 => 'orcmale',
				1 => 'orcfemale',
			),
		3 => array(
				0 => 'dwarfmale',
				1 => 'dwarffemale',
			),
		4 => array(
				0 => 'nightelfmale',
				1 => 'nightelffemale',
			),
		5 => array(
				0 => 'scourgemale',
				1 => 'scourgefemale',
			),
		6 => array(
				0 => 'taurenmale',
				1 => 'taurenfemale',
			),
		7 => array(
				0 => 'gnomemale',
				1 => 'gnomefemale',
			),
		8 => array(
				0 => 'trollmale',
				1 => 'trollfemale',
			),
		10 => array(
				0 => 'bloodelfmale',
				1 => 'bloodelffemale',
			),
		11 => array(
				0 => 'draeneimale',
				1 => 'draeneifemale',
			),
	);
	/* -------------------- */
    
	/* --- Option Counts -- */
		
		var  $opts = array(
			// Human Male
			1 => array(
				0 => array(
					'ha' => 23,
					'hc' => 12,
					'fa' => 29,
					'sk' => 14,
					'fh' => 6,
					'fc' => 12,
				),
				// Human Female
				1 => array (
					 'ha' => 16,
					 'hc' => 12,
					 'fa' => 23,
					 'sk' => 14,
					 'fh' => 8,
					 'fc' => 12,
				),
			),
		
			
			2 => array(
				//Orc Male
				0 => array(
					'ha' => 12,
					'hc' => 10,
					'fa' => 17,
					'sk' => 13,
					'fh' => 6,
					'fc' => 10,
				),
				// Orc Female
				1 => array (
					 'ha' => 11,
					'hc' => 10,
					'fa' => 17,
					'sk' => 17,
					'fh' => 10,
					'fc' => 10,
				),
			),
			
			3 => array(
				//Dwarf Male
				0 => array(
					'ha' => 18,
					'hc' => 12,
					'fa' => 19,
					'sk' => 13,
					'fh' => 5,
					'fc' => 12,
				),
				// Dwarf Female
				1 => array (
					'ha' => 15,
					'hc' => 12,
					'fa' => 19,
					'sk' => 21,
					'fh' => 10,
					'fc' => 12,
				),
			),
			
			4 => array(
				// Night Elf Male
				0 => array(
					'ha' => 11,
					'hc' => 9,
					'fa' => 17,
					'sk' => 11,
					'fh' => 9,
					'fc' => 10,
				),
				// Night Elf Female
				1 => array (
					'ha' => 11,
					'hc' => 9,
					'fa' => 17,
					'sk' => 11,
					'fh' => 5,
					'fc' => 10,
				),
			),
			
			5 => array(
				//Forsaken Male
				0 => array(
					'ha' => 14,
					'hc' => 9,
					'fa' => 19,
					'sk' => 5,
					'fh' => 7,
					'fc' => 9,
				),
				// Forsaken Female
				1 => array (
					'ha' => 14,
					'hc' => 9,
					'fa' => 19,
					'sk' => 5,
					'fh' => 16,
					'fc' => 9,
				),
			),
			
			6 => array(
				//Tauren Male
				0 => array(
					'ha' => 11,
					'hc' => 2,
					'fa' => 7,
					'sk' => 13,
					'fh' => 4,
					'fc' => 2,
				),
				// Tauren Female
				1 => array (
					'ha' => 12,
					'hc' => 2,
					'fa' => 9,
					'sk' => 21,
					'fh' => 6,
					'fc' => 2,
				),
			),
			
			7 => array(
				// Gnome Male
				0 => array(
					'ha' => 11,
					'hc' => 11,
					'fa' => 13,
					'sk' => 9,
					'fh' => 6,
					'fc' => 11,
				),
				// Gnome Female
				1 => array (
					'ha' => 11,
					'hc' => 11,
					'fa' => 13,
					'sk' => 9,
					'fh' => 7,
					'fc' => 11,
				),
			),
			
			8 => array(
				// Troll Male
				0 => array(
					'ha' => 9,
					'hc' => 12,
					'fa' => 11,
					'sk' => 17,
					'fh' => 5,
					'fc' => 12,	
				),
				// Troll Female
				1 => array (
					'ha' => 9,
					'hc' => 12,
					'fa' => 9,
					'sk' => 17,
					'fh' => 10,
					'fc' => 12,
				),
			),
			
			10 => array(
				//Blood Elf Male
				0 => array(
					'ha' => 19,
					'hc' => 12,
					'fa' => 19,
					'sk' => 18,
					'fh' => 10,
					'fc' => 12,
				),
				// Blood Elf Female
				1 => array (
					'ha' => 15,
					'hc' => 12,
					'fa' => 19,
					'sk' => 18,
					'fh' => 9,
					'fc' => 12,
				),
			),
			
			11 => array(
				//Draenei Male
				0 => array(
					'ha' => 15,
					'hc' => 9,
					'fa' => 19,
					'sk' => 14,
					'fh' => 6,
					'fc' => 9,
				),
				// Draenei Female
				1 => array (
					'ha' => 13,
					'hc' => 9,
					'fa' => 19,
					'sk' => 16,
					'fh' => 7,
					'fc' => 9,
				),
			),
		);
				
    var $default_options = array(
            'cname' => '', 
            'realm' => '',
            'realmType' => '',
            'show_top' => true,
            'show_g' => true,
            'show_p' => true,
            'show_a' => true,
            'lang' => 'En',
            'linkback' => false,
            'talents' => true,
            'show3D' => false,
            'hair' => 0,
            'hairColor' => 0,
            'face' => 0,
            'skinColor' => 0,
            'facialHair' => 0,
            'facialHairColor' => 0,
            'show_apoints' => 1,
            'title' => 'Armory for %NAME%',
    );
    
    
			

  function WoWArmory() {
        $this->plugin_folder = get_option('home').'/'.PLUGINDIR.'/wow-armory/';
        wp_enqueue_script('wowhead',"http://static.wowhead.com/widgets/power.js");
        wp_enqueue_style('wow_armory_css', $this->plugin_folder.'css/style.css');      
    }

    function init() {
        if (!$options = get_option('widget_wow_armory'))
            $options = array();
            
        $widget_ops = array('classname' => 'widget_wow_armory', 'description' => 'WoW Armory');
        $control_ops = array('width' => 500, 'height' => 100, 'id_base' => 'wowarmory');
        $name = 'WoW Armory';
        
        $registered = false;
        foreach (array_keys($options) as $o) {
            if (!isset($options[$o]['cname']))
                continue;
                
            $id = "wowarmory-$o";
            $registered = true;
            wp_register_sidebar_widget($id, $name, array(&$this, 'widget'), $widget_ops, array( 'number' => $o ) );
            wp_register_widget_control($id, $name, array(&$this, 'control'), $control_ops, array( 'number' => $o ) );
        }
        if (!$registered) {
            wp_register_sidebar_widget('wowarmory-1', $name, array(&$this, 'widget'), $widget_ops, array( 'number' => -1 ) );
            wp_register_widget_control('wowarmory-1', $name, array(&$this, 'control'), $control_ops, array( 'number' => -1 ) );
        }
    }

    function widget($args, $widget_args = 1) {
        
        extract($args);
        global $post;

        if (is_numeric($widget_args))
            $widget_args = array('number' => $widget_args);
        $widget_args = wp_parse_args($widget_args, array( 'number' => -1 ));
        extract($widget_args, EXTR_SKIP);
        $options_all = get_option('widget_wow_armory');
        if (!isset($options_all[$number]))
            return;

        $options = $options_all[$number];

        echo $before_widget;
        echo $before_title . str_replace('%NAME%',  $options['cname'], $options['title']) . $after_title;	   
        echo '<div id="armory-'.$number.'" class="armory_display">';
        $armory = getArmory($options);
        echo $armory['content'];
        echo "</div>$after_widget";
    }

		function control($widget_args = 1) {
				global $wp_registered_widgets;
				static $updated = false;
				if ( is_numeric($widget_args) )
						$widget_args = array('number' => $widget_args);
				$widget_args = wp_parse_args($widget_args, array('number' => -1));
				extract($widget_args, EXTR_SKIP);
				$options_all = get_option('widget_wow_armory');
				if (!is_array($options_all))
						$options_all = array();  
						
				if (!$updated && !empty($_POST['sidebar'])) {
						$sidebar = (string)$_POST['sidebar'];

						$sidebars_widgets = wp_get_sidebars_widgets();
						if (isset($sidebars_widgets[$sidebar]))
								$this_sidebar =& $sidebars_widgets[$sidebar];
						else
								$this_sidebar = array();

						foreach ($this_sidebar as $_widget_id) {
								if ('widget_wow_armory' == $wp_registered_widgets[$_widget_id]['callback'] && isset($wp_registered_widgets[$_widget_id]['params'][0]['number'])) {
										$widget_number = $wp_registered_widgets[$_widget_id]['params'][0]['number'];
										if (!in_array("wowarmory-$widget_number", $_POST['widget-id']))
												unset($options_all[$widget_number]);
								}
						}
						
						foreach ((array)$_POST['widget_wow_armory'] as $widget_number => $posted) {
								if (!isset($posted['cname']) && isset($options_all[$widget_number]))
										continue;
								
								$options = array();
								$options['cname'] = stripslashes($posted['cname']);
								$options['realm'] = stripslashes($posted['realm']);
								$options['realmType'] = $posted['realmType'];
								$options['show_g'] = $posted['show_g'];
								$options['show_p'] = $posted['show_p'];
								$options['show_a'] = $posted['show_a'];
								$options['lang'] = $posted['lang'];
								$options['linkback'] = $posted['linkback'];
								$options['talents'] = $posted['talents'];
								$options['show3D'] = $posted['show3D'];
								$options['hair'] = $posted['hair'];
								$options['hairColor'] = $posted['hairColor'];
								$options['face'] = $posted['face'];
								$options['skinColor'] = $posted['skinColor'];
								$options['facialHair'] = $posted['facialHair'];
								$options['facialHairColor'] = $posted['facialHairColor'];
								$options['show_top'] = $posted['show_top'];
								$options['show_apoints'] = $posted['show_apoints'];
								$options['title'] = $posted['title'];
								$options_all[$widget_number] = $options;
						}
						update_option('widget_wow_armory', $options_all);
						$updated = true;
				}

				if (-1 == $number) {
						$number = '%i%';
						$values = $this->default_options;
				}
				else {
						$values = $options_all[$number];
				}        
				
				?>
				<div class="wow_armory_options">
				<label for="widget_wow_armory[<?php echo $number; ?>[title]">Title:<br/>
				<input class="wa-title" id="widget_wow_armory-<?php echo $number; ?>-title" name="widget_wow_armory[<?php echo $number; ?>][title]" type="text" value="<?php echo stripslashes($values['title']); ?>" style="width:100%;"/><br/><small>Enter the Title for this Widget. Use %NAME% for the character's name.</small></label><br/><br/>
				<label for="widget_wow_armory[<?php echo $number; ?>][cname]">Character Name:<br/>
				<input class="wa-cname" id="widget_wow_armory-<?php echo $number; ?>-cname" name="widget_wow_armory[<?php echo $number; ?>][cname]" type="text" value="<?php echo stripslashes($values['cname']); ?>" style="width:100%;"/><br/><small>Enter the Name of the Character you wish to Display.</small></label><br/><br/>
				<label for="widget_wow_armory[<?php echo $number; ?>][realm]">Realm:<br/>
				<input class="wa-realm" id="widget_wow_armory-<?php echo $number; ?>-realm" name="widget_wow_armory[<?php echo $number; ?>][realm]" type="text" value="<?php echo stripslashes($values['realm']); ?>" style="width:440px;"/>
				<select class="wa-realmtype" id="widget_wow_armory-<?php echo $number; ?>-realmType" name="widget_wow_armory[<?php echo $number; ?>][realmType]" />
					<option value="US"<?php echo $values['realmType'] == 'US' ? ' selected="selected"' : ''; ?>>US</option>
					<option value="EU"<?php echo $values['realmType'] == 'EU' ? ' selected="selected"' : ''; ?>>EU</option>
				</select><br/><small>Enter the Character's Realm and Realm Type.</small></label><br/><br/>
				<label for="widget_wow_armory[<?php echo $number; ?>][lang]">Language: 
				<select class="wa-lang" style="width: 100;" id="widget_wow_armory-<?php echo $number; ?>-lang" name="widget_wow_armory[<?php echo $number; ?>][lang]" />
					<option value="en"<?php echo $values['lang'] == 'en' ? ' selected="selected"' : ''; ?>>English</option>
					<option value="de"<?php echo $values['lang'] == 'de' ? ' selected="selected"' : ''; ?>>Deutsch</option>
					<option value="es"<?php echo $values['lang'] == 'es' ? ' selected="selected"' : ''; ?>><?php echo html_entity_decode('Espa&Atilde;&plusmn;ol'); ?></option>
					<option value="fr"<?php echo $values['lang'] == 'fr' ? ' selected="selected"' : ''; ?>><?php echo html_entity_decode('Fran&Atilde;&sect;ais'); ?></option>
					<option value="ru"<?php echo $values['lang'] == 'ru' ? ' selected="selected"' : ''; ?>>Pycc<?php echo html_entity_decode('&ETH;&ordm;&ETH;&cedil;&ETH;&sup1;'); ?></option>
				</select><br/><small>Choose the Language you would like to display the Item Tooltips in.</small></label><br/><br/>
				<label>Display Options: <br/>
				<label for="show_top">Show Top: <input id="widget_wow_armory-<?php echo $number; ?>-show_top" name="widget_wow_armory[<?php echo $number; ?>][show_top]" type="checkbox" value="1"<?php echo $values['show_top'] ? ' checked' : ''; ?>/></label><br />
				<label for="talents">Show Talents: <input id="widget_wow_armory-<?php echo $number; ?>-talents" name="widget_wow_armory[<?php echo $number; ?>][talents]" type="checkbox" value="1"<?php echo $values['talents'] ? ' checked' : ''; ?>/></label><br />
				<label for="show_g">Show Gear: <input id="widget_wow_armory-<?php echo $number; ?>-show_g" name="widget_wow_armory[<?php echo $number; ?>][show_g]" type="checkbox" value="1"<?php echo $values['show_g'] ? ' checked' : ''; ?>/></label><br/>
				<label for="show_p">Show Professions: <input id="widget_wow_armory-<?php echo $number; ?>-show_p" name="widget_wow_armory[<?php echo $number; ?>][show_p]" type="checkbox" value="1"<?php echo $values['show_p'] ? ' checked' : ''; ?>/></label><br/>
				<label for="show_apoints">Show Achievement Points: <select style="width: 100;" id="widget_wow_armory-<?php echo $number; ?>-show_apoints" name="widget_wow_armory[<?php echo $number; ?>][show_apoints]" />
					<option value="1"<?php echo $values['show_apoints'] == '1' ? ' selected="selected"' : ''; ?>>Display Bars</option>
					<option value="2"<?php echo $values['show_apoints'] == '2' ? ' selected="selected"' : ''; ?>>Display Text Only</option>
					<option value="0"<?php echo $values['show_apoints'] == '0' ? ' selected="selected"' : ''; ?>>Display None</option>
				</select><br/><small>Choose how Achievement Points should be displayed.</small></label><br/>
				<label for="show_a">Show Achievements: <input id="widget_wow_armory-<?php echo $number; ?>-show_a" name="widget_wow_armory[<?php echo $number; ?>][show_a]" type="checkbox" value="1"<?php echo $values['show_a'] ? ' checked' : ''; ?>/><label><br />
				<small>If any of these items are checked they will be shown on the Widget.</small>
				</label><br/><br/>
				<label for="linkback">Show an Optional link back to Tim's World?
				<input id="widget_wow_armory-<?php echo $number; ?>-linkback" name="widget_wow_armory[<?php echo $number; ?>][linkback]" type="checkbox" value="1"<?php echo $values['linkback'] ? ' checked' : ''; ?> /><br/><small>If checked, a small link back to my site will be shown at the bottom of the Widget.</small></label><br/><br/>
				<label for="show3D">Show a 3D Model of your Character? <input class="wa-show3d" id="widget_wow_armory-<?php echo $number; ?>-show3D" name="widget_wow_armory[<?php echo $number; ?>][show3D]" type="checkbox" value="1"<?php echo $values['show3D'] ? ' checked' : ''; ?> /><br/><small>If checked the Widget will display a 3D model of the Character.</small></label><br/><br/>
				<div class="wa-3DOnly" style="display:<?php echo $values['show3D'] ? 'inline' : 'none'; ?>;width:100%;"><div style="height:400px;width:100%;text-align:center;">
					<?php
					
					$armory = getArmory(
						array(
							'cname' => stripslashes($values['cname']) ,
							'realm' => stripslashes($values['realm']),
							'realmType' => stripslashes($values['realmType']),
							'show_g' => 0,
							'show_p' => 0,
							'show_a' => 0,
							'lang' => $values['lang'],
							'linkback' => 0,
							'talents' => 0,
							'show3D' => 1,
							'hair' => $values['hair'],
							'hairColor' => $values['hairColor'],
							'face' => $values['face'],
							'skinColor' => $values['skinColor'],
							'facialHair' => $values['facialHair'],
							'facialHairColor' => $values['facialHairColor'],
							'show_top' => 0,
							'show_apoints' => 0
						)
					);
					?>
					<div class="wa-model"><?php echo $armory['content']; ?></div>
					<div class="wa-load"><img src="<?php echo $this->plugin_folder; ?>/includes/ajax-loader.gif" /></div>
					<br/><input type="button" class="button widget-action edit wa-refresh" id="widget_wow_armory-<?php echo $number; ?>-refresh" name="widget_wow_armory[<?php echo $number; ?>][refresh]" value="Refresh" />
					</div>
										<?php
					$thisChar = $this->opts[$armory['raceid']][$armory["genderid"]];
					$model = $this->modelNames[$armory['raceid']][$armory["genderid"]];
					?>
					<br/><br/><small>Select the styles below for this Character's appearance and then click the "Refresh" button to preview your changes.</small>
<div style="text-align:center;">
					<table style="width:100%;text-align:center;"><tr><td style="text-align:center;">
					<label for="hair">Hair Style<br/>
					<select class="wa-hair" style="width: 100;" id="widget_wow_armory-<?php echo $number; ?>-hair" name="widget_wow_armory[<?php echo $number; ?>][hair]" />
						<?php for ($i = 0; $i<=$thisChar['ha'];$i++) { ?> 
						<option value="<?php echo $i; ?>"<?php echo ($values['hair'] == $i) ? ' selected' : ''; ?>><?php echo $i; ?></option>
						<?php } ?>
					</select></label>
					</td><td style="text-align:center;">
					<label for="hairColor">Hair Color<br/>
					<select class="wa-haircolor" style="width: 100;" id="widget_wow_armory-<?php echo $number; ?>-hairColor" name="widget_wow_armory[<?php echo $number; ?>][hairColor]" />
						<?php for ($i = 0; $i<=$thisChar['hc'];$i++) { ?> 
						<option value="<?php echo $i; ?>"<?php echo ($values['hairColor'] == $i) ? ' selected' : ''; ?>><?php echo $i; ?></option>
						<?php } ?>
					</select></label>
					</td><td style="text-align:center;">
					<label for="face">Face<br/>
					<select class="wa-face" style="width: 100;" id="widget_wow_armory-<?php echo $number; ?>-face" name="widget_wow_armory[<?php echo $number; ?>][face]" />
						<?php for ($i = 0; $i<=$thisChar['fa'];$i++) { ?> 
						<option value="<?php echo $i; ?>"<?php echo ($values['face'] == $i) ? ' selected' : ''; ?>><?php echo $i; ?></option>
						<?php } ?>
					</select></label>
					</td></tr><tr><td style="text-align:center;">
					<label for="skinColor">Skin Color<br/>
					<select class="wa-skincolor" style="width: 100;" id="widget_wow_armory-<?php echo $number; ?>-skinColor" name="widget_wow_armory[<?php echo $number; ?>][skinColor]" />
						<?php for ($i = 0; $i<=$thisChar['sk'];$i++) { ?> 
						<option value="<?php echo $i; ?>"<?php echo ($values['skinColor'] == $i) ? ' selected' : ''; ?>><?php echo $i; ?></option>
						<?php } ?>
					</select></label>
					</td><td style="text-align:center;">
					<label for="facialHair">Facial Hair<br/>
					<select class="wa-facialhair" style="width: 100;" id="widget_wow_armory-<?php echo $number; ?>-facialHair" name="widget_wow_armory[<?php echo $number; ?>][facialHair]" />
						<?php for ($i = 0; $i<=$thisChar['fh'];$i++) { ?> 
						<option value="<?php echo $i; ?>"<?php echo ($values['facialHair'] == $i) ? ' selected' : ''; ?>><?php echo $i; ?></option>
						<?php } ?>
					</select></label>
					</td><td style="text-align:center;">
					<label for="facialHairColor">Facial Hair Color<br/>
					<select class="wa-facialcolor" style="width: 100;" id="widget_wow_armory-<?php echo $number; ?>-facialHairColor" name="widget_wow_armory[<?php echo $number; ?>][facialHairColor]" />
						<?php for ($i = 0; $i<=$thisChar['fc'];$i++) { ?> 
						<option value="<?php echo $i; ?>"<?php echo ($values['facialHairColor'] == $i) ? ' selected' : ''; ?>><?php echo $i; ?></option>
						<?php } ?>
					</select></label>
					</td></tr></table></div>

				</div>
				</div>
				<?php
				
		}
		
		function addFromShortcode($atts, $content = null) {
			extract(shortcode_atts(array(
					'char' => '', 
					'realm' => '',
					'realmtype' => 'US',
					'gear' => 1,
					'profs' => 1,
					'achievs' => 1,
					'lang' => 'en',
					'linkback' => 0,
					'talents' => 1,
					'model' => 0,
					'hair' => 0,
					'hairColor' => 0,
					'face' => 0,
					'skinColor' => 0,
					'facialHair' => 0,
					'facialHairC' => 0,
					'top' => 1,
					'apoints' => 1,
				), $atts));
				
			$randNo = rand(0, pow(10, 5));
			$results = '<div id="armory-'.$randNo.'" class="armory_display">';
			$armory = getArmory(array(
				'cname' => $char,
				'realm' => $realm,
				'realmType' => $realmtype,
				'show_g' => $gear,
				'show_p' => $profs,
				'show_a' => $achievs,
				'lang' => $lang,
				'linkback' => $linkback,
				'talents' => $talents,
				'show3D' => $model,
				'hair' => $hair,
				'hairColor' => $hairColor,
				'face' => $face,
				'skinColor' => $skinColor,
				'facialHair' => $facialHair,
				'facialHairColor' => $facialHairC,
				'show_top' => $top,
				'show_apoints' => $apoints,
				)
			);
			$results .= $armory['content'];
			$results .= '</div>';
			return "$results";
		}
		
		
	}
function wowarmory_options_page() {
$wrmAdmin = new WoWArmory();
	?>
	<div class="wrap">
		<h2>wow-armory Cache Administration</h2>
		<form id="cache-list" action="" method="get">
			<input type="hidden" value="wowarmorycache" name="page" />
			
			<div class="tablenav">
				<input type="submit" value="Refresh" name="refresh" class="button-secondary" />
				<input type="submit" value="Clear Cache" name="deleteit" class="button-secondary delete" />
				<br class="clear" />
			</div>

			<br class="clear" />
			
			<table class="widefat">
				<thead>
					<tr>
						<th scope="col" class="check-column"><input type="checkbox" onclick="checkAll(document.getElementById('cache-list'));" /></th>
						<th scope="col">Character Name</th>
						<th scope="col">Realm</th>
						<th scope="col">Realm Type</th>
						<th scope="col">Last Cache</th>
						<th scope="col"></th>
					</tr>
				</thead>
				
				<tbody>
					<?php 
						global $wpdb;
						$caches = $wpdb->get_results("SELECT * FROM ".(($table_prefix)?$table_prefix:'wp_')."options WHERE `option_name` LIKE '%lastarmory%' ");
						if (count($caches)==0) {
						?>
							<tr>
								<td scope="row" colspan="4" style="text-align: center;"><strong>No Caches Found</strong></td>
							</tr>
						<?php
						} else {
							foreach ($caches as $cache) {
								$currentCache = get_option($cache->option_name);
								$parser = xml_parser_create();
								xml_parse_into_struct($parser,$currentCache['data'],$vals,$index);
								xml_parser_free($parser);
								$char_info = $vals[$index["CHARACTERINFO"][0]]["attributes"];
								$char_attr = $vals[$index["CHARACTER"][0]]["attributes"];
								$armory = getArmory(array(
										'cname' => $char_attr["NAME"] ,
										'realm' => $char_attr["REALM"],
										'realmType' => $currentCache['realmType'],
										'show_g' => 1,
										'show_p' => 1,
										'show_a' => 1,
										'lang' => $currentCache['lang'],
										'linkback' => 1,
										'talents' => 1,
										'show3D' => 1,
										'hair' => 0,
										'hairColor' => 0,
										'face' => 0,
										'skinColor' => 0,
										'facialHair' => 0,
										'facialHairColor' => 0,
										'show_top' => 1,
										'show_apoints' => 1,
										'title' => 'Armory for %NAME%',
									)
								);
								?>
								<tr>
									<th scope="row" class="check-column"><input type="checkbox" name="delete[]" value="<?php echo $cache->option_name; ?>" /></th>
									<td scope="row" style="text-align: left"><img src="http://www.wowarmory.com/images/icons/race/<?php echo $char_attr['RACEID'].'-'.$char_attr['GENDERID']; ?>.gif"/> <img src="http://www.wowarmory.com/images/icons/class/<?php echo $char_attr['CLASSID']; ?>.gif" /> <?php echo $char_attr["NAME"]; ?></td>
									<td scope="row" style="text-align: left"><?php echo $char_attr["REALM"]; ?></td>
									<td scope="row" style="width:60px;text-align: left"><?php echo $currentCache['realmType']; ?></td>
									<td scope="row" style="text-align: left"><?php echo date("F j, Y, g:i a", $currentCache['lastarmorycheck']); ?></td>
									<td scope="row" style="width:140px;text-align:center;"><input alt="#TB_inline?height=500&width=400&inlineId=cache-<?php echo $cache->option_name; ?>" title="Armory for <?php echo $char_attr["NAME"]; ?>" class="thickbox button-secondary" type="button" value="View &raquo;" />
									<div id="cache-<?php echo $cache->option_name; ?>" style="display:none;"><?php 
									
									
									echo $armory['content'];
									
									 ?></div></td>
								
								</tr>
								<?php
							}
						}
					?>
				</tbody>
			</table>
			<div class="tablenav">
				<br class="clear" />
			</div>
		</form>	
	</div>
	<?php
}

function wowarmory_add_pages() {
			$page_name = add_options_page('wow-armory Cache Administration', 'wow-armory Cache', 8, 'wowarmorycache', 'wowarmory_options_page');
			add_action('admin_head-'.$page_name,'thickbox_css');
		}

function thickbox_css() {
	
	echo '<link rel="stylesheet" href="'.get_bloginfo('wpurl').'/wp-content/plugins/wow-armory/includes/thickbox/thickbox.css" type="text/css" />';

}


function wowarmory_admin_scripts() {
	wp_enqueue_script('thickbox-compressed',get_bloginfo('wpurl') . '/wp-content/plugins/wow-armory/includes/thickbox/thickbox-compressed.js', array('jquery'));
	wp_enqueue_script('wow-armory-effects',get_bloginfo('wpurl') . '/wp-content/plugins/wow-armory/includes/effects.js', array('jquery'));
	wp_enqueue_script('jquery-autocomplete',get_bloginfo('wpurl') . '/wp-content/plugins/wow-armory/includes/jquery.autocomplete.js', array('jquery'));
}


$wrm = new WoWArmory();
add_action('widgets_init', array($wrm, 'init'));
add_shortcode("wowarmory", array($wrm, 'addFromShortcode'));
add_action('admin_menu', 'wowarmory_add_pages');
add_action('admin_init', 'wowarmory_admin_scripts');

?>